package system;

import bean.MediaBean;
import bean.MediaType;
import dao.DAO;
import dao.MediaDAO;


/**
 * Abstract class responsible for the operations of medias
 * @author Otavio Lima, Laura Dutra
 *
 */
public abstract class Media {
	
	
	private MediaBean bean;
	protected static DAO<MediaBean> mediaDao = MediaDAO.getInstance();
	
	/**
	 * Default constructor for Media
	 * @param id - id of media
	 * @param url - url of media
	 * @param description - description of media
	 */
	public Media(String id, String url, String description, MediaType type, String owner) {
		
		bean = new MediaBean(id, url, description, type, owner);
		if(!mediaDao.contains(bean))
			mediaDao.save(bean);
	}
	
	/**
	 * Deletes media from system
	 */
	public void delete(){
		mediaDao.delete(bean);
	}
	
	
	/**
	 * Returns url of media
	 * @return url of media
	 */
	public String getURL(){
		return bean.getURL();
	}
	
	/**
	 * Returns id of media
	 * @return id of media
	 */
	public String getID(){
		return bean.getId();
	}
	
	/**
	 * Returns description of media
	 * @return description of media
	 */
	public String getDescription(){
		return bean.getDescription();
	}
	
	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Media))
			return false;
		Media other = (Media) obj;
		if (bean == null) {
			if (other.bean != null)
				return false;
		} else if (!bean.equals(other.bean))
			return false;
		return true;
	}

}
